package com.renaud.tvSpy.graphicsTool;


import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.KeyListener;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelListener;

import javax.swing.JPanel;


public class Offscreen extends JPanel{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7927839937475130643L;
	
	
	private JImageBuffer backbuffer;
	private int largeur;
	private int hauteur;
	
//	
//	public Offscreen(JImageBuffer backBuffer) {
//		this.backbuffer = backBuffer;
//	}
	
	public Offscreen(int largeur,int hauteur) {
		this.largeur = largeur;
		this.hauteur = hauteur;
		this.backbuffer = new JImageBuffer(new Color(255,0,255),this.largeur,this.hauteur);
	}
	 
	
	public void resizeBackbuffer(int largeur,int hauteur){
		this.largeur = largeur;
		this.hauteur = hauteur;
		this.backbuffer = new JImageBuffer(new Color(255,0,255),this.largeur,this.hauteur);
	}
	
	
	public JImageBuffer getBackbuffer() {
		return backbuffer;
	}




	




	public int getLargeur() {
		return largeur;
	}


	public int getHauteur() {
		return hauteur;
	}


	protected void paintComponent(Graphics g){
		
		
		if(this.backbuffer != null)	g.drawImage(this.backbuffer.getImage(), 0, 0, null);
		
		
		g.dispose();
	}
	
	public void cleanListener(){
		for(MouseListener l : this.getMouseListeners()){
			this.removeMouseListener(l);
		}
		for(MouseMotionListener l : this.getMouseMotionListeners()){
			this.removeMouseMotionListener(l);
		}
		for(MouseWheelListener l : this.getMouseWheelListeners()){
			this.removeMouseWheelListener(l);
		}
		for(KeyListener l : this.getKeyListeners()){
			this.removeKeyListener(l);
		}
	}



	public void setBackbuffer(JImageBuffer backbuffer) {
		this.backbuffer = backbuffer;
	}

	
	
	
	
}
